package com.zc.controller;

import com.zc.pojo.Staff;
import com.zc.service.StaffService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

/**
 * @description:
 * @author: cong
 * @create: 2024/12/27
 */
@RestController
@Slf4j
public class StaffController {
    @Autowired
    private StaffService staffService;

    @GetMapping("/getStaffById/{id}")
    public Staff getStaffById(@PathVariable Integer id) {
        Staff staff = null;
        try {
            staff = staffService.selectUserById(id);
        } catch (Exception e) {
            log.info("查询异常：" + e.getMessage());
        }
        return staff;
    }


    @PostMapping("/updateStaff")
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public int updateStaff(@RequestBody Staff staff) {
        int count = staffService.updateStaff(staff);
//        int result = 1 / 0;
        return count;
    }

    @GetMapping("/testCache")
    public String testCache() {
        return staffService.testCache();
    }
}
